package com.superteam.zzl.adapter.RecommendFragmentAdapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.superteam.zzl.activity.R;
import com.superteam.zzl.model.RecommendFragment.MainData;

import java.util.ArrayList;

/**
 * Created by zhang on 2017/1/9.
 */

/**
 * 推荐页面的推荐城市适配器
 */

public class GvCityAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<MainData.HolidayBeanX.HolidayBean> list;

    public GvCityAdapter(Context context, ArrayList<MainData.HolidayBeanX.HolidayBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.recommendfragment_item_gv,null);
            vh = new ViewHolder();
            vh.iv = (ImageView)convertView.findViewById(R.id.iv_gv_city);
            vh.tv = (TextView)convertView.findViewById(R.id.tv_gv_city);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv.setText(list.get(position).getTitle());
        Glide.with(context).load(list.get(position).getSrc()).into(vh.iv);
        return convertView;
    }

    class ViewHolder{
        ImageView iv;
        TextView tv;
    }
}
